package cn.kust.microtourismcommon.pojo.dto;


import cn.kust.microtourismcommon.constant.CommonStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author WY
 * @data 2022/7/5 9:11
 **/
@Data
@Accessors(chain = true) // 链式调用，每次调用方法返回对象
public class ResponseResult<T> {
    private int code;
    private String message;
    private T data;



    public static  ResponseResult success(){
        return new ResponseResult().setCode(CommonStatusEnum.SUCCESS.getCode()).setMessage(CommonStatusEnum.SUCCESS.getValue()).setData(null);
    }



    /**
     * 有数据响应成功
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResponseResult success(T data) {
        return new ResponseResult().setCode(CommonStatusEnum.SUCCESS.getCode()).setMessage(CommonStatusEnum.SUCCESS.getValue()).setData(data);
    }

    /**
     * 默认失败
     * @param data
     * @return
     */
    public static <T> ResponseResult fail(T data) {
        return new ResponseResult().setCode(CommonStatusEnum.FAIL.getCode()).setMessage(CommonStatusEnum.FAIL.getValue()).setData(data);
    }


    /**
     * 自定义无数据失败
     * @param code
     * @param msg
     * @return
     */
    public static ResponseResult fail(int code, String msg){
        return new ResponseResult().setCode(code).setMessage(msg);
    }

    /**
     * 自定义有数据失败
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static <T> ResponseResult fail(int code, String msg,T data){
        return new ResponseResult().setCode(code).setMessage(msg).setData(data);

    }
}
